﻿@model Lead2012.ViewModels.FieldViewModel

@{
    ViewBag.Title = "Quản lý trường dữ liệu";
    Layout = "~/Views/Shared/_Layout.cshtml";
    int i = 0;
    int j = 0;
}

<div id="apps" class="content">
	<h2 class="app">
		<span class="viewtitle"><strong>Quản lý trường dữ liệu</strong></span>
	</h2>                
    <div class="title nomargin">
		<h3>Các trường <a href="javascript:void(0)" class="group">Thêm mới nhóm</a></h3>
        
	</div>
    <div class="linegroup">
        <table class="tablegrid" cellspacing="0" border="0">
            <thead>
                <tr class="title">           
		            <th>
                        <span class="w">
                            Sắp xếp             
                        </span>
                    </th>        
		            <th>
                        <span class="w">
                            Tên             
                        </span>
                    </th>   
		            <th class="active centeralign">
                        <span class="w">
                            Loại dữ liệu          
                        </span>
                    </th> 
		            <th class="active centeralign">
                        <span class="w">
                            Loại khách hàng             
                        </span>
                    </th>
		            <th class="active centeralign">
                        <span class="w">
                            Yêu cầu
                        </span>
                    </th>
		            <th class="active centeralign">
                        <span class="w">
                            Hiển thị         
                        </span>
                    </th>
                    <th class="active centeralign">
                        <span class="w">
                            Cho phép in            
                        </span>
                    </th>
		            <th class="datetime last centeralign"><span class="w">Hành động</span></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var group in Model.ListFields)
                {
                    i++;
                    if (Model.ListFields.Count == 1)
                    {
                        Html.RenderPartial("GroupFieldItems", group, new ViewDataDictionary { { "GroupIndex", "One" } });
                    }
                    else
                    {
                        if (i == 1)
                        {
                            Html.RenderPartial("GroupFieldItems", group, new ViewDataDictionary { { "GroupIndex", "First" } });
                        }
                        else if (i == Model.ListFields.Count)
                        {
                            Html.RenderPartial("GroupFieldItems", group, new ViewDataDictionary { { "GroupIndex", "Last" } });
                        }
                        else
                        {
                            Html.RenderPartial("GroupFieldItems", group, new ViewDataDictionary { { "GroupIndex", "" } });                        
                        }
                    }
                    
                    // section showing here
                    if (group.Groups != null && group.Groups.Count > 0)
                    {
                        j = 0;
                        foreach (var item in group.Groups)
                        {
                            j++;
                            if (group.Groups.Count == 1)
                            {
                                Html.RenderPartial("SectionFieldItems", item, new ViewDataDictionary { { "SectionIndex", "One" } });
                            }
                            else
                            {
                                if (j == 1)
                                {
                                    Html.RenderPartial("SectionFieldItems", item, new ViewDataDictionary { { "SectionIndex", "First" } });
                                }
                                else if (j == group.Groups.Count())
                                {
                                    Html.RenderPartial("SectionFieldItems", item, new ViewDataDictionary { { "SectionIndex", "Last" } });
                                }
                                else
                                {
                                    Html.RenderPartial("SectionFieldItems", item, new ViewDataDictionary { { "SectionIndex", "" } });
                                }
                            }
                        }
                    }
                }
            </tbody>
        </table>
    </div>
    
</div>
@Html.Partial("AddEditGroupItem")
@Html.Partial("AddEditFieldItem")
@Html.Partial("AddEditItems")
@Html.Partial("GroupFieldAlert")
<script type="text/javascript">
    var data = @(Html.Raw(Json.Encode(Model)));
</script>
<script src="/Scripts/viewModel/FieldSetupViewModel.js" type="text/javascript"></script>
